
package com.wonder.common.common;

import java.util.HashMap;
import java.util.Map;
import com.wonder.common.exception.ExceptionCodeEnum;
import com.wonder.common.utils.MessageUtils;

public class AjaxMap {

	private static Map<String, Object> data = new HashMap<String, Object>();

	protected AjaxMap() {
	}

	public static Map<String, Object> success() {
		data.clear();
		data.put("status", ExceptionCodeEnum.SUCCESS.getCode());
		data.put("msg", ExceptionCodeEnum.SUCCESS.getMessage());
		data.put("msgId", ExceptionCodeEnum.SUCCESS.getMsgId());
		return data;
	}

	public static Map<String, Object> success(String key, Object object) {
		data.clear();
		data.put("status", ExceptionCodeEnum.SUCCESS.getCode());
		data.put("msg", ExceptionCodeEnum.SUCCESS.getMessage());
		data.put("msgId",ExceptionCodeEnum.SUCCESS.getMsgId());
		data.put(key, object);
		return data;
	}

	public static Map<String, Object> success(String key, Object object, String msg) {
		data.clear();
		data.put("status", ExceptionCodeEnum.SUCCESS.getCode());
		data.put("msg", msg);
		data.put("msgid", msg);
		data.put(key, object);
		return data;
	}

	public static Map<String, Object> success(Map<String, Object> map) {
		data.clear();
		data.putAll(map);
		data.put("status", ExceptionCodeEnum.SUCCESS.getCode());
		data.put("msg", ExceptionCodeEnum.SUCCESS.getMessage());
		data.put("msgId", ExceptionCodeEnum.SUCCESS.getMsgId());
		return data;
	}

	public static Map<String, Object> success(Map<String, Object> map, String msg) {
		data.clear();
		data.putAll(map);
		data.put("status", ExceptionCodeEnum.SUCCESS.getCode());
		data.put("msg", msg);
		data.put("msgid", msg);
		return data;
	}
	
	public static Map<String, Object> success( String msg) {
		data.clear();
		data.put("status", ExceptionCodeEnum.SUCCESS.getCode());
		data.put("msg", msg);
		data.put("msgid", msg);
		return data;
	}
	
	public static Map<String, Object> formatSuccess( String msg) {
		data.clear();
		data.put("status", ExceptionCodeEnum.SUCCESS.getCode());
		data.put("msg", MessageUtils.message(msg));
		return data;
	}

	public static Map<String, Object> failed(String msg, String key, Object object) {
		data.clear();
		data.put("status", ExceptionCodeEnum.FAILED.getCode());
		data.put("msg", msg);
		data.put("msgid", msg);
		data.put(key, object);
		return data;
	}
	
	public static Map<String, Object> failed(Map<String, Object> map,String msg) {
		data.clear();
		data.put("status", ExceptionCodeEnum.FAILED.getCode());
		data.put("msg", msg);
		data.put("msgid", msg);
		data.putAll(map);
		return data;
	}

	public static Map<String, Object> failed(String msg) {
		data.clear();
		data.put("status", ExceptionCodeEnum.FAILED.getCode());
		data.put("msg", msg);
		data.put("msgId", msg);
		return data;
	}
	
	public static Map<String, Object> unauthorized(String msg) {
		data.clear();
		data.put("status", ExceptionCodeEnum.UNAUTHORIZED.getCode());
		data.put("msg", msg);
		return data;
	}
	
	public static Map<String, Object> unauthorized() {
		data.clear();
		data.put("status", ExceptionCodeEnum.UNAUTHORIZED.getCode());
		data.put("msg", ExceptionCodeEnum.UNAUTHORIZED.getMessage());
		data.put("msgId",ExceptionCodeEnum.UNAUTHORIZED.getMsgId());
		return data;
	}
	
	public static Map<String, Object> failed(String msg,String msgId) {
		data.clear();
		data.put("status", ExceptionCodeEnum.FAILED.getCode());
		data.put("msg", msg);
		data.put("msgId", msgId);
		return data;
	}
	
	public static Map<String, Object> formatFailed(String msg) {
		data.clear();
		data.put("status", ExceptionCodeEnum.PRAM_NOT_MATCH.getCode());
		data.put("msg", MessageUtils.message(msg));
		return data;
	}

	public static Map<String, Object> formatFailed(String msg , String msgId) {
		data.clear();
		data.put("status", ExceptionCodeEnum.PRAM_NOT_MATCH.getCode());
		data.put("msg", MessageUtils.message(msg));
		data.put("msgId", msgId);
		return data;
	}


}
